package br.ufmg.vod.wbr.algorithims.bfs;

//import static br.ufmg.vod.test.TestConfig.*;
import java.util.Map;

import junit.framework.TestCase;
import br.ufmg.vod.test.FastJungDirectedGraph;
import br.ufmg.vod.test.TestConfig;
import br.ufmg.vod.wbr.graphs.FastDirectedGraph;
import br.ufmg.vod.wbr.graphs.IDXGraphLoader;
import edu.uci.ics.jung.algorithms.shortestpath.BFSDistanceLabeler;
import edu.uci.ics.jung.algorithms.shortestpath.DijkstraDistance;

public class FastBFSTest extends TestCase {
	
	private FastJungDirectedGraph jungGraph;
	private FastDirectedGraph directedGraph;
	
	
	@Override
	protected void setUp() throws Exception {
		jungGraph = new FastJungDirectedGraph(TestConfig.inLinkIdx, TestConfig.inLink, TestConfig.outLinkIdx, TestConfig.outLink, TestConfig.sample, TestConfig.sampleSize); 
		directedGraph = new IDXGraphLoader(TestConfig.inLinkIdx, TestConfig.inLink, TestConfig.outLinkIdx, TestConfig.outLink, TestConfig.sample, TestConfig.sampleSize).loadGraph();
		super.setUp();
	}

	public void testBfsSingleVertex() {
		
		BFSDistanceLabeler<Integer, Long> jungBFS = new BFSDistanceLabeler<Integer, Long>();
		DijkstraDistance<Integer, Long> jungDijkstra = new DijkstraDistance<Integer, Long>(jungGraph);
		FastBFS directedDijkstra = new FastBFS(directedGraph);
		
		Map<Integer, Number> distanceMap = jungDijkstra.getDistanceMap(0);
		
		BFSData directedBFSData = directedDijkstra.bfsSingleVertex(0);
		jungBFS.labelDistances(jungGraph, 0);
		assertEquals(distanceMap.keySet().size(), directedBFSData.visitedQueue.size());
		for (int i = 0; i < directedBFSData.visitedQueue.size(); i++) {
			int visitedVertex = directedBFSData.visitedQueue.peek(i);
			assertTrue( distanceMap.containsKey( visitedVertex ) );
			assertEquals( distanceMap.get(visitedVertex).intValue(), directedBFSData.dist[visitedVertex]);
			assertEquals( (int)jungBFS.getVerticesInOrderVisited().get(i), visitedVertex);
		}
		
		
	}

}
